# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=libsndfile

pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.0.25
pkgrel=2
pkgdesc="A C library for reading and writing files containing sampled sound (mingw-w64)"
arch=('any')
url="http://www.mega-nerd.com/libsndfile"
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-flac" "${MINGW_PACKAGE_PREFIX}-libvorbis")
options=('staticlibs' 'strip')
source=(http://www.mega-nerd.com/libsndfile/files/${_realname}-${pkgver}.tar.gz
    0001-more-elegant-and-foolproof-autogen-fallback.all.patch
    0002-conditional-truncate.mingw.patch
    0003-fix-source-searches.mingw.patch
    0004-fix-linking-external-libs.patch)
md5sums=('e2b7bb637e01022c7d20f95f9c3990a2'
         '9b4254acf1cfc17a1e94af29f7260d30'
         'c9ac8330da543496b0b5cb6ae081a7b6'
         'f225019fdc006262cae9bb0ca91bc446'
         '4417bf29cc527d9d9e0ac2e42a5695a0')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0001-more-elegant-and-foolproof-autogen-fallback.all.patch
  patch -p1 -i ${srcdir}/0002-conditional-truncate.mingw.patch
  patch -p1 -i ${srcdir}/0003-fix-source-searches.mingw.patch
  patch -p1 -i ${srcdir}/0004-fix-linking-external-libs.patch

  #sed -i 's|#!/usr/bin/python|#!/usr/bin/python2|' src/binheader_writef_check.py \
  #  src/create_symbols_file.py programs/test-sndfile-metadata-set.py
  autoreconf -fi -I M4
}

build() {
  mkdir -p ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}
  ../${_realname}-${pkgver}/configure \
    --enable-shared \
    --enable-static \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --disable-sqlite \
    --disable-test-coverage \
    --enable-external-libs
    #--enable-experimental # speex support
  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install
}
